package com.dubito.composewidgets.ui.progressbutton.component

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * author: LiLiang
 * createTime: 2022/10/5-20:22
 * remark:
 **/

@Composable
fun ProgressButton() {
    Surface(modifier = Modifier.fillMaxSize(), color = Color.Gray) {
        var loading by remember {
            mutableStateOf(false)
        }
        Box {
            ProgressButtonComponents(
                modifier = Modifier
                    .padding(16.dp)
                    .height(46.dp)
                    .align(Alignment.Center),
                onClick = { loading = !loading },
                color = MaterialTheme.colors.secondary,
                progressColor = MaterialTheme.colors.background,
                loading = loading
            ) {
                Text(text = "刷新")
            }
        }
    }
}

@Preview
@Composable
fun ProgressButtonPreview() {
    ProgressButton()
}